fix: Grid items overlap after returning from an extended background#593
Open
MatiPl01 wants to merge 2 commits into
Open
fix: Grid items overlap after returning from an extended background#593MatiPl01 wants to merge 2 commits into
MatiPl01 wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
The AppState re-seed only matters once the grid uses absolute positioning; in relative flow there are no absolute positions to restore, so gate it on usesAbsoluteLayout and make it a no-op otherwise. Also correct the explanatory comment to describe the real mechanism: a recreated native view never receives the last emitted style because the shared value did not change, so re-assigning each inactive item's position (a fresh object) forces Reanimated to re-push the style, reproducing what the first drag would otherwise do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #592.
Sortable.Grid/Sortable.Flexitem positions are driven entirely by Reanimated shared values and are never re-established when the app returns to the foreground. After an extended background, the platform can recreate the sortable's native views (and Reanimated may not re-run the mappers that position them), so the absolutely positioned items commit stale, overlapping positions and stay overlapped until a drag re-runs the layout.On
AppStatebecomingactivethis now:onLayoutevents fired by recreated views are treated as fresh measurements instead of being diffed away, anditemLayoutPositions) so the freshly committed views pick it up.Shared between grid and flex; the currently dragged item is skipped, and the re-seed is a no-op while the grid is still in relative layout (nothing absolute to restore).
Before / after
Verification
Tested on an Android emulator (RN 0.86, Reanimated 4.5.1, Fabric). The failure mode was reproduced by injecting the resume-stale state that the "fixed by a drag" clue implies: the applied
position.values go stale whileitemHeightsanditemLayoutPositionsstay correct. Temporary logging on resume shows the fix restoring each item's position from the authoritative layout:So the overlap recovers on the next foreground with no drag, and the handler does nothing (writes back identical values) when the layout is already correct. Expand/collapse, dynamic-height
+ Addreflow, and drag-reorder all keep working.Also re-verified on the iOS fabric example (New Arch) as a direct A/B with the same injected resume-stale state:
Note: this validates the fix against the failure mechanism (injected), not the un-forceable natural OS-reclaim trigger, which could not be reproduced on the available hardware (an emulator and a 12 GB device both keep the surface alive across an Activity finish). Reporter confirmation on the original device would close that last gap.
Follow-up commit
Refines the original change: gates the resume re-seed on
usesAbsoluteLayoutso it is skipped entirely while the grid is still in relative flow, and rewrites the explanatory comment to describe the real mechanism (a recreated native view never receives the last emitted style because the shared value did not change; re-assigning each inactive item's position as a fresh object forces Reanimated to re-push it, which is exactly what the first drag would otherwise do).